<template>
	<view>
		<!-- 自定义导航 -->
		<uni-nav-bar left-icon="back" :title="title" @clickLeft="backTo()" statusBar></uni-nav-bar>
		<!-- 列表 -->
		<view class="search-list" v-for="(item, index) in data" :key="index" @click="toDetail(item.id)">
			<view :class="{ topone: index == 0, toptwo: index == 1, topthree: index == 2, topother: index > 2 }">
				{{ index + 1 }}
			</view>
			<image :src="item.cover" class="cover" mode="widthFix"></image>
			<view>
				<view>{{ item.name }}</view>
				<view>{{ item.desc }}</view>
				<view>{{ item.author }} · {{ item.min }}</view>
			</view>
		</view>
	</view>
</template>

<script>
export default {
	data() {
		return {
			data: [],
			title:''
		};
	},
	methods: {
		// 返回
		backTo() {
			uni.navigateBack({
				delta: 1
			});
		},
		// 获取列表数据
		getData(cate) {
			uni.request({
				url: `${getApp().globalData.baseURL}/v1/novel/catelist/${cate}`,
				success: res => {
					console.log(res);
					this.data = res.data.data;
				}
			});
		},
		// 跳转图书详情页面
		toDetail(id) {
			uni.navigateTo({
				url: `/pages/bookDetail/bookDetail?id=${id}`
			});
		}
	},
	onLoad(options) {
		console.log(options);
		this.getData(options.cate);
		this.title=options.title
	}
};
</script>

<style lang="scss" scoped>
// 图书封面
.cover {
	width: 130rpx;
	border-radius: 0 10rpx 10rpx 0;
}
.search-list {
	height: 172rpx;
	padding: 24rpx;
	display: flex;
	justify-content: space-between;
	align-items: center;
	> view:first-child {
		font-weight: 600;
		font-size: 36rpx;
		padding: 0 10rpx;
	}
	> view:last-child {
		padding-right: 10rpx;
		display: flex;
		flex-direction: column;
		justify-content: space-around;
		height: 100%;
		> view:first-child {
			font-weight: 600;
			font-size: 32rpx;
		}
		> view:nth-child(2) {
			color: #999;
			width: 480rpx;
			overflow: hidden;
			white-space: nowrap;
			text-overflow: ellipsis;
		}
		> view:last-child {
			color: #666;
		}
	}
}
.topone {
	color: #ff604f;
}
.toptwo {
	color: #ff8956;
}
.topthree {
	color: #feb200;
}
.topother {
	color: #666;
}
</style>
